import pymysql

def type_count() :
    host = "ring1"
    port = 3306
    db = "movie_analysis"
    username = "root"
    password = "root"

    counts = {}

    connect = pymysql.connect(host=host, port=port, db=db, user=username, password=password)
    cursor = connect.cursor()

    cursor.execute("select * from movies")
    movies = cursor.fetchall()

    for movie in movies:
        types = movie[4]

        for movie_type in types.split('/'):
            num = counts.get(movie_type, 0)
            counts[movie_type] = num + 1

    return counts


if __name__ == '__main__':
    count = type_count()
    print(count)
